package com.sevensoft.controller;

import com.sevensoft.properties.PcProperties;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/webhooks")
@RequiredArgsConstructor
public class WebHooksController {

    private final PcProperties properties;

    @RequestMapping("/onPush")
    public String onPush(HttpServletRequest request) {
        String defaultBranc = request.getParameter("default_branc");
        System.err.println(defaultBranc);
        String authCode = request.getHeader(properties.getAuthHeader());
        System.err.println(authCode);
        if ( properties.getSign().equals(authCode) || properties.getPwd().equals(authCode) ) {
            log.info("onPush!!!!!!!!!!!");
            return "ok";
        }
        log.error("error auth");
        return "no auth";
    }
}
